package logic

import (
	"context"
	"errors"
	"novel-world/model/mysql"
	"strings"

	"novel-world/novelrpc/internal/svc"
	"novel-world/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *novelrpc.GoodsAddRequest) (*novelrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line
	user := &mysql.Goods{
		UserId:  int(in.UserId),
		NovelId: int(in.NovelId),
		Comment: in.Comment,
	}
	if strings.Contains(in.Comment, "抄袭") || strings.Contains(in.Comment, "涉政") {
		return nil, errors.New("包含敏感词")
	}
	if err := user.GoodsAdd(mysql.DB); err != nil {
		return nil, err
	}
	return &novelrpc.GoodsAddResponse{
		GoodsId: int64(user.ID),
	}, nil
}
